#!/usr/bin/env bash

# bash比awk慢一个数量级

code_len=8
rec_qt=100000

CHARS=(0 1 2 3 4 5 6 7 8 9
        A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
CHARS_LEN=${#CHARS[*]}

declare -A codes

count=0
while (( count < rec_qt ))
do
    i=0
    code=""
    while (( i < code_len ))
    do
        rand=$RANDOM
        (( index=rand % CHARS_LEN ))
#        echo $rand $index
        code=${code}${CHARS[$index]}
        (( ++i ))
    done
#    echo $code
    if (( codes[$code] == 1 ))
    then
        echo "$code duplicate, continue"
        continue
    fi
    codes[$code]=1

    (( ++count ))
    if (( count % 10000 == 0 ))
    then
        echo "$count finish"
    fi
done

code_file=code2.txt
rm -fr $code_file
for k in ${!codes[*]}
do
    echo $k >>$code_file
done
